<?php
class Router extends SleekRouter {
	public function __construct (array $routes) {
		parent::__construct($routes, WEBROOT, MOD_REWRITE, HOME_PAGE);
	}

	public function urlForStyle ($site, $style, $type = 'css') {
		return WEBROOT . "Sites/$site/Styles/$style.$type?" . @filemtime(DOCROOT . "Sites/$site/Styles/$style.$type");
	}

	public function getModule () {
		return false;
	}

	public function setSelectedLink ($links) {
		$newLinks		= $links;
		$url			= $_SERVER['REQUEST_URI'];
		$url			= explode('?', $url);
		$url			= $url[0];
		$tmpSelected	= array('url' => '', 'selected' => false);
		$numLinks		= count($newLinks);

		for ($i = 0; $i < $numLinks; $i++) {
			$newLinks[$i]['selected'] = false;

			if (strpos($url, $newLinks[$i]['url']) === 0 and strlen($tmpSelected['url']) < strlen($newLinks[$i]['url'])) {
				$tmpSelected['selected'] = false;

				$newLinks[$i]['selected'] = true;

				$tmpSelected = &$newLinks[$i];
			}
		}

		# If the default page is selected and we're not on it, deselect it
		$homeURL = $this->urlFor(HOME_PAGE);

		for ($i = 0; $i < $numLinks; $i++) {
			if ($newLinks[$i]['selected'] and $newLinks[$i]['url'] == $homeURL and $url != $homeURL) {
				$newLinks[$i]['selected'] = false;
			}
		}

		return $newLinks;
	}
}
